/*
 * 文件名：StsQaJobCoreServiceImpl9_10.java
 * 版权：Copyright by www.yunshows.com
 * 描述：
 * 修改人：Awoke
 * 修改时间：2020年2月18日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

package top.infopub.job.sts.service.impl;


import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.infopub.exception.ServiceException;
import top.infopub.job.fia.domain.ProBudgetDetailDomain;
import top.infopub.job.fia.service.IncomeBillService;
import top.infopub.job.fia.service.PayBillService;
import top.infopub.job.fia.service.ProBudgetDetailService;
import top.infopub.job.fia.service.ProBudgetService;
import top.infopub.job.hr.service.OrgInfoService;
import top.infopub.job.mkt.service.PreProjectService;
import top.infopub.job.sts.service.OrgAreaQaService;
import top.infopub.job.sts.service.OrgProQaService;
import top.infopub.job.sts.service.OrgSuperQaService;
import top.infopub.job.sts.service.ProCashinPoolService;
import top.infopub.job.sts.service.ProCashoutPoolService;
import top.infopub.job.sts.service.StsQaJobCoreService9_10;
import top.infopub.job.util.ParserUtil;
import top.infopub.model.fia.ProBudget;
import top.infopub.model.fia.ProBudgetDetail;
import top.infopub.model.hr.OrgInfo;
import top.infopub.model.sts.OrgAreaQa;
import top.infopub.model.sts.OrgProQa;
import top.infopub.model.sts.OrgSuperQa;
import top.infopub.model.sts.ProCashinPool;
import top.infopub.model.sts.ProCashoutPool;
import top.infopub.tdp.util.BizParaUtil;

import com.google.common.collect.Maps;

/**
 * 经营质量分析报表 数据归集汇总核心service 为给job服务</br>
 * 9=投资性现金流入 10=投资性现金流出
 * @author Awoke
 * @version 2020年2月15日
 * @see StsQaJobCoreService9_10
 * @since
 */
@Service
@Deprecated
public class StsQaJobCoreServiceImpl9_10 implements StsQaJobCoreService9_10 {

    private static final Logger log = LoggerFactory.getLogger(StsQaJobCoreServiceImpl9_10.class);

    @Autowired
    private OrgInfoService orgInfoService;

    @Autowired
    private OrgSuperQaService orgSuperQaService;

    @Autowired
    private OrgAreaQaService orgAreaQaService;

    @Autowired
    private OrgProQaService orgProQaService;

    @Autowired
    private ProBudgetService proBudgetService;

    @Autowired
    private ProBudgetDetailService proBudgetDetailService;

    @Autowired
    private PreProjectService preProjectService;

    @Autowired
    private IncomeBillService incomeBillService;

    @Autowired
    private PayBillService payBillService;

    @Autowired
    private ProCashinPoolService proCashinPoolService;

    @Autowired
    private ProCashoutPoolService proCashoutPoolService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void stsQaOfCashinJob() {
        // 1. 新增- 项目公司经营质量 数据
        Map<String, Object> proBudgetWhere = Maps.newHashMap();
        proBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
        proBudgetWhere.put("processStatus", "9");
        // 【项目指标预算fia_pro_budget】{投资性现金流入}
        List<ProBudget> proBudgetList = proBudgetService.selectByMapWhere(proBudgetWhere);
        // 最外层的for循环 使用预算的org反查其实际完成 
        for (ProBudget var : proBudgetList) {
            OrgProQa proQaAdd = new OrgProQa();
            OrgInfo temp = new OrgInfo();
            temp.setProjectCode(var.getProCode());
            List<OrgInfo> orgs = orgInfoService.selectByEntityWhere(temp);
            // 如果公司项目没有绑定 则跳过
            if (orgs == null || orgs.isEmpty()) {
                log.info("项目：{} 与公司未绑定，统计时，skip~", var.getProCode());
                continue;
            }
            else {
                proQaAdd.setHrOrgAreaId(orgs.get(0).getParentId());
                proQaAdd.setHrOrgProId(orgs.get(0).getId());
                proQaAdd.setOrgProName(orgs.get(0).getCompName());
            }
            proQaAdd.setProCode(var.getProCode());
            proQaAdd.setProName(var.getProName());
            proQaAdd.setAimType(9);// 指标类型 9=投资性现金流入
            proQaAdd.setBelongsYear(ParserUtil.getYearOfPrevMonth());
            proQaAdd.setBelongsMonth(ParserUtil.getMonthOfPrevMonth());
            proQaAdd.setStsMonth(ParserUtil.prevMonth());// 上个月

            // 当月计划
            Map<String, Object> proBudgetDetailWhere = Maps.newHashMap();
            proBudgetDetailWhere.put("proBudgetId", var.getId());
            proBudgetDetailWhere.put("months", ParserUtil.getMonthOfPrevMonth());
            ProBudgetDetail plan = proBudgetDetailService.selectByMapWhere(proBudgetDetailWhere).get(
                0);
            proQaAdd.setCurMonthPlan(plan.getCashIn());// 原始单位：元
            proQaAdd.setCurMonthPlanTts(ParserUtil.unit2Tts(plan.getCashIn()));
            proQaAdd.setCurMonthPlanHms(ParserUtil.unit2Hms(plan.getCashIn()));
            // 年度计划
            proQaAdd.setYearAllPlan(var.getCashInSum());// 原始单位：元
            proQaAdd.setYearAllPlanTts(ParserUtil.unit2Tts(var.getCashInSum()));
            proQaAdd.setYearAllPlanHms(ParserUtil.unit2Hms(var.getCashInSum()));

            // 当月实际完成
            Map<String, Object> proQaWhere = Maps.newHashMap();
            proQaWhere.put("incomeDateStart", ParserUtil.prevMonth());
            proQaWhere.put("incomeDateEnd", ParserUtil.currentMonth());
            proQaWhere.put("hrOrgProId", proQaAdd.getHrOrgProId());
            BigDecimal proQaOfCashIn = incomeBillService.selectProQaOfCashIn(proQaWhere);
            if (proQaOfCashIn == null || proQaOfCashIn.compareTo(BigDecimal.ZERO) == 0) {
                // 实际当月完成为0
                proQaAdd.setCurMonthFinish(BigDecimal.ZERO);
                proQaAdd.setCurMonthFinishTts(BigDecimal.ZERO);
                proQaAdd.setCurMonthFinishHms(BigDecimal.ZERO);
            }
            else {
                // 实际当月完成 
                proQaAdd.setCurMonthFinish(proQaOfCashIn);
                proQaAdd.setCurMonthFinishTts(ParserUtil.unit2Tts(proQaOfCashIn));
                proQaAdd.setCurMonthFinishHms(ParserUtil.unit2Hms(proQaOfCashIn));
            }
            proQaAdd.setCurMonthRate(proQaAdd.getCurMonthFinish().divide(
                proQaAdd.getCurMonthPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));// 完成率 =实际完成/计划

            Map<String, Object> prevWhere = Maps.newHashMap();
            prevWhere.put("hrOrgProId", proQaAdd.getHrOrgProId());
            prevWhere.put("aimType", 9);// 投资性现金流入
            prevWhere.put("belongsYear", proQaAdd.getBelongsYear());
            prevWhere.put("belongsMonth", proQaAdd.getBelongsMonth() - 1);// 前一个月
            prevWhere.put("orderCondition", " add_time desc ");
            List<OrgProQa> prevList = orgProQaService.selectByMapWhere(prevWhere);

            // 月累数据   如果是当前年份的第一个月  或者 没有此前月累数据，则月累数据=当月数据  否则需要取前一个月的月累数据+当月数据 
            if (proQaAdd.getBelongsMonth() == 1 || prevList == null || prevList.isEmpty()) {
                proQaAdd.setYearAddupPlan(proQaAdd.getCurMonthPlan());
                proQaAdd.setYearAddupPlanTts(proQaAdd.getCurMonthPlanTts());
                proQaAdd.setYearAddupPlanHms(proQaAdd.getCurMonthPlanHms());
                proQaAdd.setYearAddupFinish(proQaAdd.getCurMonthFinish());
                proQaAdd.setYearAddupFinishTts(proQaAdd.getCurMonthFinishTts());
                proQaAdd.setYearAddupFinishHms(proQaAdd.getCurMonthFinishHms());
                proQaAdd.setYearAddupRate(proQaAdd.getCurMonthRate());
            }
            else {
                OrgProQa prevProQa = prevList.get(0);
                // 累加   当前月累 = 上月月累 + 当前
                proQaAdd.setYearAddupPlan(proQaAdd.getCurMonthPlan().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupPlanTts(proQaAdd.getCurMonthPlanTts().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupPlanHms(proQaAdd.getCurMonthPlanHms().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupFinish(proQaAdd.getCurMonthFinish().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupFinishTts(proQaAdd.getCurMonthFinishTts().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupFinishHms(proQaAdd.getCurMonthFinishHms().add(
                    prevProQa.getYearAddupPlan()));
                // 计算月累完成率
                proQaAdd.setYearAddupRate(proQaAdd.getYearAddupFinish().divide(
                    proQaAdd.getYearAddupPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                    ParserUtil.HUNDRED));// 完成率 =实际完成/计划
            }
            // 年度完成率  月累完成/年度计划 
            proQaAdd.setYearAllRate(proQaAdd.getYearAddupFinish().divide(
                proQaAdd.getYearAllPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));
            proQaAdd.setAddBy("system");
            proQaAdd.setAddTime(new Date());
            proQaAdd.setUptBy("system");
            proQaAdd.setUptTime(new Date());
            orgProQaService.insert(proQaAdd);

            // 以下 新增 项目投资性现金流入sts_pro_cashin_pool数据
            ProCashinPool pool = new ProCashinPool();
            pool.setProCode(proQaAdd.getProCode());
            pool.setProName(proQaAdd.getProName());
            pool.setBelongsYear(proQaAdd.getBelongsYear());
            pool.setBelongsMonth(proQaAdd.getBelongsMonth());
            pool.setStsMonth(proQaAdd.getStsMonth());
            pool.setTotalSum(proQaAdd.getCurMonthFinish());
            pool.setTotalSumTts(proQaAdd.getCurMonthFinishTts());

            Map<String, Object> proPoolWhere = Maps.newHashMap();
            proPoolWhere.put("incomeDateStart", ParserUtil.prevMonth());
            proPoolWhere.put("incomeDateEnd", ParserUtil.currentMonth());
            proPoolWhere.put("hrOrgProId", proQaAdd.getHrOrgProId());
            // 6=项目专项基金 singleType
            proPoolWhere.put("singleType", "6");
            BigDecimal single_6 = incomeBillService.selectProSingleOfCashIn(proPoolWhere);
            pool.setSpecialFund(single_6);
            pool.setSpecialFundTts(ParserUtil.unit2Tts(single_6));
            // 8=政府补贴 singleType
            proPoolWhere.put("singleType", "8");
            BigDecimal single_8 = incomeBillService.selectProSingleOfCashIn(proPoolWhere);
            pool.setGdSubsidy(single_8);
            pool.setGdSubsidyTts(ParserUtil.unit2Tts(single_8));
            // 9=回购款 singleType
            proPoolWhere.put("singleType", "9");
            BigDecimal single_9 = incomeBillService.selectProSingleOfCashIn(proPoolWhere);
            pool.setBuyBackFee(single_9);
            pool.setBuyBackFeeTts(ParserUtil.unit2Tts(single_9));
            pool.setAddBy("system");
            pool.setAddTime(new Date());
            pool.setUptBy("system");
            pool.setUptTime(new Date());
            proCashinPoolService.insert(pool);
        }
        // 2. 新增- 区域公司经营质量 数据
        Map<String, Object> areaBudgetWhere = Maps.newHashMap();
        areaBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
        areaBudgetWhere.put("months", ParserUtil.getMonthOfPrevMonth());
        List<ProBudgetDetailDomain> areaMonthBudgetList = proBudgetDetailService.sumMonthCashInOfArea(areaBudgetWhere);
        for (ProBudgetDetailDomain var : areaMonthBudgetList) {
            if (StringUtils.isBlank(var.getHrOrgAreaId())) {
                log.info("所属区域公司ID为空，统计时，skip~");
                continue;
            }
            // 由于南充挂到总部下面，按着区域分组会汇总到，但不能计入区域数据
            if (StringUtils.endsWithIgnoreCase(var.getHrOrgAreaId(),
                BizParaUtil.get("super_org_id"))) {
                continue;
            }
            OrgAreaQa areaQaAdd = new OrgAreaQa();
            areaQaAdd.setHrOrgSuperId(BizParaUtil.get("super_org_id"));// 总部公司ID
            areaQaAdd.setHrOrgAreaId(var.getHrOrgAreaId());
            areaQaAdd.setOrgAreaName(orgInfoService.selectByPrimaryKey(var.getHrOrgAreaId()).getCompName());
            areaQaAdd.setAimType(9);// 指标类型 9=投资性现金流入
            areaQaAdd.setBelongsYear(ParserUtil.getYearOfPrevMonth());
            areaQaAdd.setBelongsMonth(ParserUtil.getMonthOfPrevMonth());
            areaQaAdd.setStsMonth(ParserUtil.prevMonth());// 上个月

            // 月度计划
            areaQaAdd.setCurMonthPlan(var.getCashIn());// 原始单位：元
            areaQaAdd.setCurMonthPlanTts(ParserUtil.unit2Tts(var.getCashIn()));
            areaQaAdd.setCurMonthPlanHms(ParserUtil.unit2Hms(var.getCashIn()));
            // 年度预算
            Map<String, Object> areaYearBudgetWhere = Maps.newHashMap();
            areaYearBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
            areaYearBudgetWhere.put("hrOrgAreaId", var.getHrOrgAreaId());
            BigDecimal areaYearBudget = proBudgetService.sumYearCashInOfArea(areaYearBudgetWhere);
            // 年度计划
            areaQaAdd.setYearAllPlan(areaYearBudget);// 原始单位：元
            areaQaAdd.setYearAllPlanTts(ParserUtil.unit2Tts(areaYearBudget));
            areaQaAdd.setYearAllPlanHms(ParserUtil.unit2Hms(areaYearBudget));

            // 当月实际完成
            Map<String, Object> qaWhere = Maps.newHashMap();
            qaWhere.put("incomeDateStart", ParserUtil.prevMonth());
            qaWhere.put("incomeDateEnd", ParserUtil.currentMonth());
            qaWhere.put("hrOrgAreaId", var.getHrOrgAreaId());
            BigDecimal areaQaOfCashIn = incomeBillService.selectAreaQaOfCashIn(qaWhere);
            if (areaQaOfCashIn == null || areaQaOfCashIn.compareTo(BigDecimal.ZERO) == 0) {
                // 实际当月完成为0
                areaQaAdd.setCurMonthFinish(BigDecimal.ZERO);
                areaQaAdd.setCurMonthFinishTts(BigDecimal.ZERO);
                areaQaAdd.setCurMonthFinishHms(BigDecimal.ZERO);
            }
            else {
                // 实际当月完成 
                areaQaAdd.setCurMonthFinish(areaQaOfCashIn);
                areaQaAdd.setCurMonthFinishTts(ParserUtil.unit2Tts(areaQaOfCashIn));
                areaQaAdd.setCurMonthFinishHms(ParserUtil.unit2Hms(areaQaOfCashIn));
            }
            areaQaAdd.setCurMonthRate(areaQaAdd.getCurMonthFinish().divide(
                areaQaAdd.getCurMonthPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));// 完成率 =实际完成/计划

            Map<String, Object> prevWhere = Maps.newHashMap();
            prevWhere.put("hrOrgAreaId", areaQaAdd.getHrOrgAreaId());
            prevWhere.put("aimType", 9);// 指标类型 9=投资性现金流入
            prevWhere.put("belongsYear", areaQaAdd.getBelongsYear());
            prevWhere.put("belongsMonth", areaQaAdd.getBelongsMonth() - 1);// 前一个月
            prevWhere.put("orderCondition", " add_time desc ");
            List<OrgAreaQa> prevList = orgAreaQaService.selectByMapWhere(prevWhere);

            // 月累数据   如果是当前年份的第一个月  或者 没有此前月累数据，则月累数据=当月数据  否则需要取前一个月的月累数据+当月数据 
            if (areaQaAdd.getBelongsMonth() == 1 || prevList == null || prevList.isEmpty()) {
                areaQaAdd.setYearAddupPlan(areaQaAdd.getCurMonthPlan());
                areaQaAdd.setYearAddupPlanTts(areaQaAdd.getCurMonthPlanTts());
                areaQaAdd.setYearAddupPlanHms(areaQaAdd.getCurMonthPlanHms());
                areaQaAdd.setYearAddupFinish(areaQaAdd.getCurMonthFinish());
                areaQaAdd.setYearAddupFinishTts(areaQaAdd.getCurMonthFinishTts());
                areaQaAdd.setYearAddupFinishHms(areaQaAdd.getCurMonthFinishHms());
                areaQaAdd.setYearAddupRate(areaQaAdd.getCurMonthRate());
            }
            else {
                OrgAreaQa prevAreaQa = prevList.get(0);
                // 累加   当前月累 = 上月月累 + 当前
                areaQaAdd.setYearAddupPlan(areaQaAdd.getCurMonthPlan().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupPlanTts(areaQaAdd.getCurMonthPlanTts().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupPlanHms(areaQaAdd.getCurMonthPlanHms().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupFinish(areaQaAdd.getCurMonthFinish().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupFinishTts(areaQaAdd.getCurMonthFinishTts().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupFinishHms(areaQaAdd.getCurMonthFinishHms().add(
                    prevAreaQa.getYearAddupPlan()));
                // 计算月累完成率
                areaQaAdd.setYearAddupRate(areaQaAdd.getYearAddupFinish().divide(
                    areaQaAdd.getYearAddupPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                    ParserUtil.HUNDRED));// 完成率 =实际完成/计划
            }
            // 年度完成率  月累完成/年度计划 
            areaQaAdd.setYearAllRate(areaQaAdd.getYearAddupFinish().divide(
                areaQaAdd.getYearAllPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));
            areaQaAdd.setAddBy("system");
            areaQaAdd.setAddTime(new Date());
            areaQaAdd.setUptBy("system");
            areaQaAdd.setUptTime(new Date());
            orgAreaQaService.insert(areaQaAdd);
        }
        // 3. 新增- 总部公司经营质量 数据
        // 月度预算
        Map<String, Object> superBudgetWhere = Maps.newHashMap();
        superBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
        superBudgetWhere.put("months", ParserUtil.getMonthOfPrevMonth());
        BigDecimal superMonthBudget = proBudgetDetailService.sumMonthCashInOfSuper(superBudgetWhere);
        if (superMonthBudget == null || superMonthBudget.compareTo(BigDecimal.ZERO) == 0) {
            throw new ServiceException("[总部]经营质量分析指标-投资性现金流入 数据归集时，公司预算不存在~");
        }
        // 年度预算
        Map<String, Object> superYearBudgetWhere = Maps.newHashMap();
        superYearBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
        BigDecimal superYearBudget = proBudgetService.sumYearCashInOfSuper(superYearBudgetWhere);
        if (superYearBudget == null || superYearBudget.compareTo(BigDecimal.ZERO) == 0) {
            throw new ServiceException("[总部]经营质量分析指标-投资性现金流入 数据归集时，公司预算不存在~");
        }

        OrgSuperQa superQaAdd = new OrgSuperQa();
        superQaAdd.setHrOrgSuperId(BizParaUtil.get("super_org_id"));// 总部公司ID
        superQaAdd.setAimType(9);// 指标类型 9=投资性现金流入
        superQaAdd.setBelongsYear(ParserUtil.getYearOfPrevMonth());
        superQaAdd.setBelongsMonth(ParserUtil.getMonthOfPrevMonth());
        superQaAdd.setStsMonth(ParserUtil.prevMonth());// 上个月
        // 月度计划
        superQaAdd.setCurMonthPlan(superMonthBudget);// 原始单位：元
        superQaAdd.setCurMonthPlanTts(ParserUtil.unit2Tts(superMonthBudget));
        superQaAdd.setCurMonthPlanHms(ParserUtil.unit2Hms(superMonthBudget));
        // 年度计划
        superQaAdd.setYearAllPlan(superYearBudget);// 原始单位：元
        superQaAdd.setYearAllPlanTts(ParserUtil.unit2Tts(superYearBudget));
        superQaAdd.setYearAllPlanHms(ParserUtil.unit2Hms(superYearBudget));

        // 当月实际完成
        Map<String, Object> qaWhere = Maps.newHashMap();
        qaWhere.put("incomeDateStart", ParserUtil.prevMonth());
        qaWhere.put("incomeDateEnd", ParserUtil.currentMonth());
        BigDecimal allQaOfCashIn = incomeBillService.selectAllProQaOfCashIn(qaWhere);
        if (allQaOfCashIn == null || allQaOfCashIn.compareTo(BigDecimal.ZERO) == 0) {
            // 实际当月完成为0
            superQaAdd.setCurMonthFinish(BigDecimal.ZERO);
            superQaAdd.setCurMonthFinishTts(BigDecimal.ZERO);
            superQaAdd.setCurMonthFinishHms(BigDecimal.ZERO);
        }
        else {
            // 实际当月完成 
            superQaAdd.setCurMonthFinish(allQaOfCashIn);
            superQaAdd.setCurMonthFinishTts(ParserUtil.unit2Tts(allQaOfCashIn));
            superQaAdd.setCurMonthFinishHms(ParserUtil.unit2Hms(allQaOfCashIn));
        }
        superQaAdd.setCurMonthRate(superQaAdd.getCurMonthFinish().divide(
            superQaAdd.getCurMonthPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(ParserUtil.HUNDRED));// 完成率 =实际完成/计划

        Map<String, Object> prevWhere = Maps.newHashMap();
        prevWhere.put("hrOrgSuperId", BizParaUtil.get("super_org_id"));// 总部公司ID
        prevWhere.put("aimType", 9);// 指标类型 9=投资性现金流入
        prevWhere.put("belongsYear", superQaAdd.getBelongsYear());
        prevWhere.put("belongsMonth", superQaAdd.getBelongsMonth() - 1);// 前一个月
        prevWhere.put("orderCondition", " add_time desc ");
        List<OrgSuperQa> prevList = orgSuperQaService.selectByMapWhere(prevWhere);

        // 月累数据   如果是当前年份的第一个月  或者 没有此前月累数据，则月累数据=当月数据  否则需要取前一个月的月累数据+当月数据 
        if (superQaAdd.getBelongsMonth() == 1 || prevList == null || prevList.isEmpty()) {
            superQaAdd.setYearAddupPlan(superQaAdd.getCurMonthPlan());
            superQaAdd.setYearAddupPlanTts(superQaAdd.getCurMonthPlanTts());
            superQaAdd.setYearAddupPlanHms(superQaAdd.getCurMonthPlanHms());
            superQaAdd.setYearAddupFinish(superQaAdd.getCurMonthFinish());
            superQaAdd.setYearAddupFinishTts(superQaAdd.getCurMonthFinishTts());
            superQaAdd.setYearAddupFinishHms(superQaAdd.getCurMonthFinishHms());
            superQaAdd.setYearAddupRate(superQaAdd.getCurMonthRate());
        }
        else {
            OrgSuperQa prevAreaQa = prevList.get(0);
            // 累加   当前月累 = 上月月累 + 当前
            superQaAdd.setYearAddupPlan(superQaAdd.getCurMonthPlan().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupPlanTts(superQaAdd.getCurMonthPlanTts().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupPlanHms(superQaAdd.getCurMonthPlanHms().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupFinish(superQaAdd.getCurMonthFinish().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupFinishTts(superQaAdd.getCurMonthFinishTts().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupFinishHms(superQaAdd.getCurMonthFinishHms().add(
                prevAreaQa.getYearAddupPlan()));
            // 计算月累完成率
            superQaAdd.setYearAddupRate(superQaAdd.getYearAddupFinish().divide(
                superQaAdd.getYearAddupPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));// 完成率 =实际完成/计划
        }
        // 年度完成率  月累完成/年度计划 
        superQaAdd.setYearAllRate(superQaAdd.getYearAddupFinish().divide(
            superQaAdd.getYearAllPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(ParserUtil.HUNDRED));
        superQaAdd.setAddBy("system");
        superQaAdd.setAddTime(new Date());
        superQaAdd.setUptBy("system");
        superQaAdd.setUptTime(new Date());
        orgSuperQaService.insert(superQaAdd);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void stsQaOfCashoutJob() {
        // 1. 新增- 项目公司经营质量 数据
        Map<String, Object> proBudgetWhere = Maps.newHashMap();
        proBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
        proBudgetWhere.put("processStatus", "9");
        // 【项目指标预算fia_pro_budget】{投资性现金流出}
        List<ProBudget> proBudgetList = proBudgetService.selectByMapWhere(proBudgetWhere);
        // 最外层的for循环 使用预算的org反查其实际完成 
        for (ProBudget var : proBudgetList) {
            OrgProQa proQaAdd = new OrgProQa();
            OrgInfo temp = new OrgInfo();
            temp.setProjectCode(var.getProCode());
            List<OrgInfo> orgs = orgInfoService.selectByEntityWhere(temp);
            // 如果公司项目没有绑定 则跳过
            if (orgs == null || orgs.isEmpty()) {
                log.info("项目：{} 与公司未绑定，统计时，skip~", var.getProCode());
                continue;
            }
            else {
                proQaAdd.setHrOrgAreaId(orgs.get(0).getParentId());
                proQaAdd.setHrOrgProId(orgs.get(0).getId());
                proQaAdd.setOrgProName(orgs.get(0).getCompName());
            }
            proQaAdd.setProCode(var.getProCode());
            proQaAdd.setProName(var.getProName());
            proQaAdd.setAimType(10);// 指标类型 10=投资性现金流出
            proQaAdd.setBelongsYear(ParserUtil.getYearOfPrevMonth());
            proQaAdd.setBelongsMonth(ParserUtil.getMonthOfPrevMonth());
            proQaAdd.setStsMonth(ParserUtil.prevMonth());// 上个月

            // 当月计划
            Map<String, Object> proBudgetDetailWhere = Maps.newHashMap();
            proBudgetDetailWhere.put("proBudgetId", var.getId());
            proBudgetDetailWhere.put("months", ParserUtil.getMonthOfPrevMonth());
            ProBudgetDetail plan = proBudgetDetailService.selectByMapWhere(proBudgetDetailWhere).get(
                0);
            proQaAdd.setCurMonthPlan(plan.getCashOut());// 原始单位：元
            proQaAdd.setCurMonthPlanTts(ParserUtil.unit2Tts(plan.getCashOut()));
            proQaAdd.setCurMonthPlanHms(ParserUtil.unit2Hms(plan.getCashOut()));
            // 年度计划
            proQaAdd.setYearAllPlan(var.getCashOutSum());// 原始单位：元
            proQaAdd.setYearAllPlanTts(ParserUtil.unit2Tts(var.getCashOutSum()));
            proQaAdd.setYearAllPlanHms(ParserUtil.unit2Hms(var.getCashOutSum()));

            // 当月实际完成
            Map<String, Object> proQaWhere = Maps.newHashMap();
            proQaWhere.put("payDateStart", ParserUtil.prevMonth());
            proQaWhere.put("payDateEnd", ParserUtil.currentMonth());
            proQaWhere.put("proCode", proQaAdd.getProCode());
            BigDecimal proQaOfCashOut = payBillService.selectProQaOfCashOut(proQaWhere);
            if (proQaOfCashOut == null || proQaOfCashOut.compareTo(BigDecimal.ZERO) == 0) {
                // 实际当月完成为0
                proQaAdd.setCurMonthFinish(BigDecimal.ZERO);
                proQaAdd.setCurMonthFinishTts(BigDecimal.ZERO);
                proQaAdd.setCurMonthFinishHms(BigDecimal.ZERO);
            }
            else {
                // 实际当月完成 
                proQaAdd.setCurMonthFinish(proQaOfCashOut);
                proQaAdd.setCurMonthFinishTts(ParserUtil.unit2Tts(proQaOfCashOut));
                proQaAdd.setCurMonthFinishHms(ParserUtil.unit2Hms(proQaOfCashOut));
            }
            proQaAdd.setCurMonthRate(proQaAdd.getCurMonthFinish().divide(
                proQaAdd.getCurMonthPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));// 完成率 =实际完成/计划

            Map<String, Object> prevWhere = Maps.newHashMap();
            prevWhere.put("hrOrgProId", proQaAdd.getHrOrgProId());
            prevWhere.put("aimType", 10);// 投资性现金流出
            prevWhere.put("belongsYear", proQaAdd.getBelongsYear());
            prevWhere.put("belongsMonth", proQaAdd.getBelongsMonth() - 1);// 前一个月
            prevWhere.put("orderCondition", " add_time desc ");
            List<OrgProQa> prevList = orgProQaService.selectByMapWhere(prevWhere);

            // 月累数据   如果是当前年份的第一个月  或者 没有此前月累数据，则月累数据=当月数据  否则需要取前一个月的月累数据+当月数据 
            if (proQaAdd.getBelongsMonth() == 1 || prevList == null || prevList.isEmpty()) {
                proQaAdd.setYearAddupPlan(proQaAdd.getCurMonthPlan());
                proQaAdd.setYearAddupPlanTts(proQaAdd.getCurMonthPlanTts());
                proQaAdd.setYearAddupPlanHms(proQaAdd.getCurMonthPlanHms());
                proQaAdd.setYearAddupFinish(proQaAdd.getCurMonthFinish());
                proQaAdd.setYearAddupFinishTts(proQaAdd.getCurMonthFinishTts());
                proQaAdd.setYearAddupFinishHms(proQaAdd.getCurMonthFinishHms());
                proQaAdd.setYearAddupRate(proQaAdd.getCurMonthRate());
            }
            else {
                OrgProQa prevProQa = prevList.get(0);
                // 累加   当前月累 = 上月月累 + 当前
                proQaAdd.setYearAddupPlan(proQaAdd.getCurMonthPlan().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupPlanTts(proQaAdd.getCurMonthPlanTts().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupPlanHms(proQaAdd.getCurMonthPlanHms().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupFinish(proQaAdd.getCurMonthFinish().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupFinishTts(proQaAdd.getCurMonthFinishTts().add(
                    prevProQa.getYearAddupPlan()));
                proQaAdd.setYearAddupFinishHms(proQaAdd.getCurMonthFinishHms().add(
                    prevProQa.getYearAddupPlan()));
                // 计算月累完成率
                proQaAdd.setYearAddupRate(proQaAdd.getYearAddupFinish().divide(
                    proQaAdd.getYearAddupPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                    ParserUtil.HUNDRED));// 完成率 =实际完成/计划
            }
            // 年度完成率  月累完成/年度计划 
            proQaAdd.setYearAllRate(proQaAdd.getYearAddupFinish().divide(
                proQaAdd.getYearAllPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));
            proQaAdd.setAddBy("system");
            proQaAdd.setAddTime(new Date());
            proQaAdd.setUptBy("system");
            proQaAdd.setUptTime(new Date());
            orgProQaService.insert(proQaAdd);

            // 以下 新增 项目投资性现金流出 sts_pro_cashout_pool数据
            ProCashoutPool pool = new ProCashoutPool();
            pool.setProCode(proQaAdd.getProCode());
            pool.setProName(proQaAdd.getProName());
            pool.setBelongsYear(proQaAdd.getBelongsYear());
            pool.setBelongsMonth(proQaAdd.getBelongsMonth());
            pool.setStsMonth(proQaAdd.getStsMonth());
            pool.setTotalSum(proQaAdd.getCurMonthFinish());
            pool.setTotalSumTts(proQaAdd.getCurMonthFinishTts());

            // 21=内部总包款 22=外部总包款 23=专业分包款 24=专业设备采购款 25=政府代付费 26=项目前期费 
            Map<String, Object> proPoolWhere = Maps.newHashMap();
            proQaWhere.put("payDateStart", ParserUtil.prevMonth());
            proQaWhere.put("payDateEnd", ParserUtil.currentMonth());
            proQaWhere.put("proCode", proQaAdd.getProCode());
            // 21=内部总包款 singleType
            proPoolWhere.put("singleType", "21");
            BigDecimal single_21 = payBillService.selectProSingleOfCashOut(proQaWhere);
            pool.setInTotalPack(single_21);
            pool.setInTotalPackTts(ParserUtil.unit2Tts(single_21));
            // 22=外部总包款 singleType
            proPoolWhere.put("singleType", "22");
            BigDecimal single_22 = payBillService.selectProSingleOfCashOut(proQaWhere);
            pool.setOutTotalPack(single_22);
            pool.setOutTotalPackTts(ParserUtil.unit2Tts(single_22));
            // 23=专业分包款 singleType
            proPoolWhere.put("singleType", "23");
            BigDecimal single_23 = payBillService.selectProSingleOfCashOut(proQaWhere);
            pool.setSubPack(single_23);
            pool.setSubPackTts(ParserUtil.unit2Tts(single_23));
            // 24=专业设备采购款 singleType
            proPoolWhere.put("singleType", "24");
            BigDecimal single_24 = payBillService.selectProSingleOfCashOut(proQaWhere);
            pool.setDeviceBuyFee(single_24);
            pool.setDeviceBuyFeeTts(ParserUtil.unit2Tts(single_24));
            // 25=政府代付费 singleType
            proPoolWhere.put("singleType", "25");
            BigDecimal single_25 = payBillService.selectProSingleOfCashOut(proQaWhere);
            pool.setGdPayFee(single_25);
            pool.setGdPayFeeTts(ParserUtil.unit2Tts(single_25));
            // 26=项目前期费  singleType
            proPoolWhere.put("singleType", "26");
            BigDecimal single_26 = payBillService.selectProSingleOfCashOut(proQaWhere);
            pool.setProPreFee(single_26);
            pool.setProPreFeeTts(ParserUtil.unit2Tts(single_26));

            pool.setAddBy("system");
            pool.setAddTime(new Date());
            pool.setUptBy("system");
            pool.setUptTime(new Date());
            proCashoutPoolService.insert(pool);
        }
        // 2. 新增- 区域公司经营质量 数据
        Map<String, Object> areaBudgetWhere = Maps.newHashMap();
        areaBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
        areaBudgetWhere.put("months", ParserUtil.getMonthOfPrevMonth());
        List<ProBudgetDetailDomain> areaMonthBudgetList = proBudgetDetailService.sumMonthCashOutOfArea(areaBudgetWhere);
        for (ProBudgetDetailDomain var : areaMonthBudgetList) {
            if (StringUtils.isBlank(var.getHrOrgAreaId())) {
                log.info("所属区域公司ID为空，统计时，skip~");
                continue;
            }
            // 由于南充挂到总部下面，按着区域分组会汇总到，但不能计入区域数据
            if (StringUtils.endsWithIgnoreCase(var.getHrOrgAreaId(),
                BizParaUtil.get("super_org_id"))) {
                continue;
            }
            OrgAreaQa areaQaAdd = new OrgAreaQa();
            areaQaAdd.setHrOrgSuperId(BizParaUtil.get("super_org_id"));// 总部公司ID
            areaQaAdd.setHrOrgAreaId(var.getHrOrgAreaId());
            areaQaAdd.setOrgAreaName(orgInfoService.selectByPrimaryKey(var.getHrOrgAreaId()).getCompName());
            areaQaAdd.setAimType(10);// 指标类型 10=投资性现金流出
            areaQaAdd.setBelongsYear(ParserUtil.getYearOfPrevMonth());
            areaQaAdd.setBelongsMonth(ParserUtil.getMonthOfPrevMonth());
            areaQaAdd.setStsMonth(ParserUtil.prevMonth());// 上个月

            // 月度计划
            areaQaAdd.setCurMonthPlan(var.getCashOut());// 原始单位：元
            areaQaAdd.setCurMonthPlanTts(ParserUtil.unit2Tts(var.getCashOut()));
            areaQaAdd.setCurMonthPlanHms(ParserUtil.unit2Hms(var.getCashOut()));
            // 年度预算
            Map<String, Object> areaYearBudgetWhere = Maps.newHashMap();
            areaYearBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
            areaYearBudgetWhere.put("hrOrgAreaId", var.getHrOrgAreaId());
            BigDecimal areaYearBudget = proBudgetService.sumYearCashOutOfArea(areaYearBudgetWhere);
            // 年度计划
            areaQaAdd.setYearAllPlan(areaYearBudget);// 原始单位：元
            areaQaAdd.setYearAllPlanTts(ParserUtil.unit2Tts(areaYearBudget));
            areaQaAdd.setYearAllPlanHms(ParserUtil.unit2Hms(areaYearBudget));

            // 当月实际完成
            Map<String, Object> qaWhere = Maps.newHashMap();
            qaWhere.put("payDateStart", ParserUtil.prevMonth());
            qaWhere.put("payDateEnd", ParserUtil.currentMonth());
            qaWhere.put("hrOrgAreaId", var.getHrOrgAreaId());
            BigDecimal areaQaOfCashOut = payBillService.selectAreaQaOfCashOut(qaWhere);
            if (areaQaOfCashOut == null || areaQaOfCashOut.compareTo(BigDecimal.ZERO) == 0) {
                // 实际当月完成为0
                areaQaAdd.setCurMonthFinish(BigDecimal.ZERO);
                areaQaAdd.setCurMonthFinishTts(BigDecimal.ZERO);
                areaQaAdd.setCurMonthFinishHms(BigDecimal.ZERO);
            }
            else {
                // 实际当月完成 
                areaQaAdd.setCurMonthFinish(areaQaOfCashOut);
                areaQaAdd.setCurMonthFinishTts(ParserUtil.unit2Tts(areaQaOfCashOut));
                areaQaAdd.setCurMonthFinishHms(ParserUtil.unit2Hms(areaQaOfCashOut));
            }
            areaQaAdd.setCurMonthRate(areaQaAdd.getCurMonthFinish().divide(
                areaQaAdd.getCurMonthPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));// 完成率 =实际完成/计划

            Map<String, Object> prevWhere = Maps.newHashMap();
            prevWhere.put("hrOrgAreaId", areaQaAdd.getHrOrgAreaId());
            prevWhere.put("aimType", 10);// 指标类型 10=投资性现金流出
            prevWhere.put("belongsYear", areaQaAdd.getBelongsYear());
            prevWhere.put("belongsMonth", areaQaAdd.getBelongsMonth() - 1);// 前一个月
            prevWhere.put("orderCondition", " add_time desc ");
            List<OrgAreaQa> prevList = orgAreaQaService.selectByMapWhere(prevWhere);

            // 月累数据   如果是当前年份的第一个月  或者 没有此前月累数据，则月累数据=当月数据  否则需要取前一个月的月累数据+当月数据 
            if (areaQaAdd.getBelongsMonth() == 1 || prevList == null || prevList.isEmpty()) {
                areaQaAdd.setYearAddupPlan(areaQaAdd.getCurMonthPlan());
                areaQaAdd.setYearAddupPlanTts(areaQaAdd.getCurMonthPlanTts());
                areaQaAdd.setYearAddupPlanHms(areaQaAdd.getCurMonthPlanHms());
                areaQaAdd.setYearAddupFinish(areaQaAdd.getCurMonthFinish());
                areaQaAdd.setYearAddupFinishTts(areaQaAdd.getCurMonthFinishTts());
                areaQaAdd.setYearAddupFinishHms(areaQaAdd.getCurMonthFinishHms());
                areaQaAdd.setYearAddupRate(areaQaAdd.getCurMonthRate());
            }
            else {
                OrgAreaQa prevAreaQa = prevList.get(0);
                // 累加   当前月累 = 上月月累 + 当前
                areaQaAdd.setYearAddupPlan(areaQaAdd.getCurMonthPlan().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupPlanTts(areaQaAdd.getCurMonthPlanTts().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupPlanHms(areaQaAdd.getCurMonthPlanHms().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupFinish(areaQaAdd.getCurMonthFinish().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupFinishTts(areaQaAdd.getCurMonthFinishTts().add(
                    prevAreaQa.getYearAddupPlan()));
                areaQaAdd.setYearAddupFinishHms(areaQaAdd.getCurMonthFinishHms().add(
                    prevAreaQa.getYearAddupPlan()));
                // 计算月累完成率
                areaQaAdd.setYearAddupRate(areaQaAdd.getYearAddupFinish().divide(
                    areaQaAdd.getYearAddupPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                    ParserUtil.HUNDRED));// 完成率 =实际完成/计划
            }
            // 年度完成率  月累完成/年度计划 
            areaQaAdd.setYearAllRate(areaQaAdd.getYearAddupFinish().divide(
                areaQaAdd.getYearAllPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));
            areaQaAdd.setAddBy("system");
            areaQaAdd.setAddTime(new Date());
            areaQaAdd.setUptBy("system");
            areaQaAdd.setUptTime(new Date());
            orgAreaQaService.insert(areaQaAdd);
        }
        // 3. 新增- 总部公司经营质量 数据
        // 月度预算
        Map<String, Object> superBudgetWhere = Maps.newHashMap();
        superBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
        superBudgetWhere.put("months", ParserUtil.getMonthOfPrevMonth());
        BigDecimal superMonthBudget = proBudgetDetailService.sumMonthCashOutOfSuper(superBudgetWhere);
        if (superMonthBudget == null || superMonthBudget.compareTo(BigDecimal.ZERO) == 0) {
            throw new ServiceException("[总部]经营质量分析指标-投资性现金流出 数据归集时，公司预算不存在~");
        }
        // 年度预算
        Map<String, Object> superYearBudgetWhere = Maps.newHashMap();
        superYearBudgetWhere.put("belongsYear", ParserUtil.getYearOfPrevMonth());
        BigDecimal superYearBudget = proBudgetService.sumYearCashOutOfSuper(superYearBudgetWhere);
        if (superYearBudget == null || superYearBudget.compareTo(BigDecimal.ZERO) == 0) {
            throw new ServiceException("[总部]经营质量分析指标-投资性现金流出 数据归集时，公司预算不存在~");
        }

        OrgSuperQa superQaAdd = new OrgSuperQa();
        superQaAdd.setHrOrgSuperId(BizParaUtil.get("super_org_id"));// 总部公司ID
        superQaAdd.setAimType(10);// 指标类型 10=投资性现金流出
        superQaAdd.setBelongsYear(ParserUtil.getYearOfPrevMonth());
        superQaAdd.setBelongsMonth(ParserUtil.getMonthOfPrevMonth());
        superQaAdd.setStsMonth(ParserUtil.prevMonth());// 上个月
        // 月度计划
        superQaAdd.setCurMonthPlan(superMonthBudget);// 原始单位：元
        superQaAdd.setCurMonthPlanTts(ParserUtil.unit2Tts(superMonthBudget));
        superQaAdd.setCurMonthPlanHms(ParserUtil.unit2Hms(superMonthBudget));
        // 年度计划
        superQaAdd.setYearAllPlan(superYearBudget);// 原始单位：元
        superQaAdd.setYearAllPlanTts(ParserUtil.unit2Tts(superYearBudget));
        superQaAdd.setYearAllPlanHms(ParserUtil.unit2Hms(superYearBudget));

        // 当月实际完成
        Map<String, Object> qaWhere = Maps.newHashMap();
        qaWhere.put("payDateStart", ParserUtil.prevMonth());
        qaWhere.put("payDateEnd", ParserUtil.currentMonth());
        BigDecimal allQaOfCashOut = payBillService.selectAllProQaOfCashOut(qaWhere);
        if (allQaOfCashOut == null || allQaOfCashOut.compareTo(BigDecimal.ZERO) == 0) {
            // 实际当月完成为0
            superQaAdd.setCurMonthFinish(BigDecimal.ZERO);
            superQaAdd.setCurMonthFinishTts(BigDecimal.ZERO);
            superQaAdd.setCurMonthFinishHms(BigDecimal.ZERO);
        }
        else {
            // 实际当月完成 
            superQaAdd.setCurMonthFinish(allQaOfCashOut);
            superQaAdd.setCurMonthFinishTts(ParserUtil.unit2Tts(allQaOfCashOut));
            superQaAdd.setCurMonthFinishHms(ParserUtil.unit2Hms(allQaOfCashOut));
        }
        superQaAdd.setCurMonthRate(superQaAdd.getCurMonthFinish().divide(
            superQaAdd.getCurMonthPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(ParserUtil.HUNDRED));// 完成率 =实际完成/计划

        Map<String, Object> prevWhere = Maps.newHashMap();
        prevWhere.put("hrOrgSuperId", BizParaUtil.get("super_org_id"));// 总部公司ID
        prevWhere.put("aimType", 10);// 指标类型 10=投资性现金流出
        prevWhere.put("belongsYear", superQaAdd.getBelongsYear());
        prevWhere.put("belongsMonth", superQaAdd.getBelongsMonth() - 1);// 前一个月
        prevWhere.put("orderCondition", " add_time desc ");
        List<OrgSuperQa> prevList = orgSuperQaService.selectByMapWhere(prevWhere);

        // 月累数据   如果是当前年份的第一个月  或者 没有此前月累数据，则月累数据=当月数据  否则需要取前一个月的月累数据+当月数据 
        if (superQaAdd.getBelongsMonth() == 1 || prevList == null || prevList.isEmpty()) {
            superQaAdd.setYearAddupPlan(superQaAdd.getCurMonthPlan());
            superQaAdd.setYearAddupPlanTts(superQaAdd.getCurMonthPlanTts());
            superQaAdd.setYearAddupPlanHms(superQaAdd.getCurMonthPlanHms());
            superQaAdd.setYearAddupFinish(superQaAdd.getCurMonthFinish());
            superQaAdd.setYearAddupFinishTts(superQaAdd.getCurMonthFinishTts());
            superQaAdd.setYearAddupFinishHms(superQaAdd.getCurMonthFinishHms());
            superQaAdd.setYearAddupRate(superQaAdd.getCurMonthRate());
        }
        else {
            OrgSuperQa prevAreaQa = prevList.get(0);
            // 累加   当前月累 = 上月月累 + 当前
            superQaAdd.setYearAddupPlan(superQaAdd.getCurMonthPlan().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupPlanTts(superQaAdd.getCurMonthPlanTts().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupPlanHms(superQaAdd.getCurMonthPlanHms().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupFinish(superQaAdd.getCurMonthFinish().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupFinishTts(superQaAdd.getCurMonthFinishTts().add(
                prevAreaQa.getYearAddupPlan()));
            superQaAdd.setYearAddupFinishHms(superQaAdd.getCurMonthFinishHms().add(
                prevAreaQa.getYearAddupPlan()));
            // 计算月累完成率
            superQaAdd.setYearAddupRate(superQaAdd.getYearAddupFinish().divide(
                superQaAdd.getYearAddupPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(
                ParserUtil.HUNDRED));// 完成率 =实际完成/计划
        }
        // 年度完成率  月累完成/年度计划 
        superQaAdd.setYearAllRate(superQaAdd.getYearAddupFinish().divide(
            superQaAdd.getYearAllPlan(), 4, BigDecimal.ROUND_HALF_UP).multiply(ParserUtil.HUNDRED));
        superQaAdd.setAddBy("system");
        superQaAdd.setAddTime(new Date());
        superQaAdd.setUptBy("system");
        superQaAdd.setUptTime(new Date());
        orgSuperQaService.insert(superQaAdd);
    }

}
